package com.blockmeta.bbs.overallserviceapplication.search.adapter;

import androidx.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;

import com.blockmeta.bbs.baselibrary.base.adapter.BaseAdapter;
import com.blockmeta.bbs.baselibrary.utils.FormatUtil;
import com.blockmeta.bbs.baselibrary.utils.SharedPreferenceUtil;
import com.blockmeta.bbs.businesslibrary.arouter.RouterHelper;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.businesslibrary.constant.Constant;
import com.blockmeta.bbs.businesslibrary.util.ColorUtil;
import com.blockmeta.bbs.overallserviceapplication.R;
import com.blockmeta.bbs.businesslibrary.pojo.SearchCoinsPOJO;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * Created by author on 2018/1/30.
 */

public class CoinsSearchAdapter1 extends BaseAdapter<SearchCoinsPOJO.RankingBean,BaseViewHolder> {
    public CoinsSearchAdapter1(int layoutResId, @Nullable List<SearchCoinsPOJO.RankingBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final SearchCoinsPOJO.RankingBean item) {
        helper.setText(R.id.list_item_tv1,"#"+item.getIndex()+" "+item.getName());
        helper.setText(R.id.list_item_tv2,item.getSymbol());
        long total = FormatUtil.parseLong(item.getTotal().replaceAll(",", "").trim());
        helper.setText(R.id.list_item_tv3,"市值＄ " + FormatUtil.longToVolumeHumanReadableFormat(total,2));
        helper.setText(R.id.list_item_tv4, "¥ " + FormatUtil.usd2cny(item.getPrice()
                , SharedPreferenceUtil.getFloat(mContext, Constant.CNY_USD, 6.4f)));

        helper.setText(R.id.list_item_tv4_down, "＄ " + item.getPrice());
        //百分比计算

        helper.setText(R.id.list_item_tv5,item.getChange()+"%");

        String change = TextUtils.isEmpty(item.getChange())?"-1":item.getChange();

        if (Double.parseDouble(change) < 0){
            helper.setText(R.id.list_item_tv5,item.getChange()+"%");
            helper.setBackgroundRes(R.id.list_item_tv5, ColorUtil.getDownsBg());
        }else {
            helper.setText(R.id.list_item_tv5,"+"+item.getChange()+"%");
            helper.setBackgroundRes(R.id.list_item_tv5, ColorUtil.getUpsBg());
        }

        RelativeLayout view = helper.getView(R.id.list_choice_main);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                RouterHelper.startActivity(mContext, RouterPath.RANK_DETAIL_ACTIVITY,item.getSymbol(),item.getCoinKey());
            }
        });

        helper.setVisible(R.id.iv_collection,false);
    }


}
